<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<link href="style.css" type="text/css" rel="stylesheet">
<title>SHLD—Double Precision Shift Left </title></head>
<body>
<h1>SHLD—Double Precision Shift Left</h1>
<table>
<tr>
<th>Opcode*</th>
<th>Instruction</th>
<th>Op/En</th>
<th>64-Bit Mode</th>
<th>Compat/Leg Mode</th>
<th>Description</th></tr>
<tr>
<td>0F A4 /r ib</td>
<td>SHLD <em>r/m16, r16, imm8</em></td>
<td>MRI</td>
<td>Valid</td>
<td>Valid</td>
<td>Shift<em> r/m16</em> to left <em>imm8</em> places while shifting bits from <em>r16</em> in from the right.</td></tr>
<tr>
<td>0F A5 /r</td>
<td>SHLD <em>r/m16, r16</em>, CL</td>
<td>MRC</td>
<td>Valid</td>
<td>Valid</td>
<td>Shift<em> r/m16</em> to left CL places while shifting bits from <em>r16</em> in from the right.</td></tr>
<tr>
<td>0F A4 /r ib</td>
<td>SHLD <em>r/m32, r32, imm8</em></td>
<td>MRI</td>
<td>Valid</td>
<td>Valid</td>
<td>Shift<em> r/m32</em> to left <em>imm8</em> places while shifting bits from <em>r32</em> in from the right.</td></tr>
<tr>
<td>REX.W + 0F A4 /r ib</td>
<td>SHLD <em>r/m64, r64, imm8</em></td>
<td>MRI</td>
<td>Valid</td>
<td>N.E.</td>
<td>Shift<em> r/m64</em> to left <em>imm8</em> places while shifting bits from <em>r64</em> in from the right.</td></tr>
<tr>
<td>0F A5 /r</td>
<td>SHLD <em>r/m32, r32</em>, CL</td>
<td>MRC</td>
<td>Valid</td>
<td>Valid</td>
<td>Shift<em> r/m32</em> to left CL places while shifting bits from <em>r32</em> in from the right.</td></tr>
<tr>
<td>REX.W + 0F A5 /r</td>
<td>SHLD <em>r/m64, r64</em>, CL</td>
<td>MRC</td>
<td>Valid</td>
<td>N.E.</td>
<td>Shift<em> r/m64 </em>to left CL places while shifting bits from <em>r64</em> in from the right.</td></tr></table>
<h3>Instruction Operand Encoding</h3>
<table>
<tr>
<td>Op/En</td>
<td>Operand 1</td>
<td>Operand 2</td>
<td>Operand 3</td>
<td>Operand 4</td></tr>
<tr>
<td>MRI</td>
<td>ModRM:r/m (w)</td>
<td>ModRM:reg (r)</td>
<td>imm8</td>
<td>NA</td></tr>
<tr>
<td>MRC</td>
<td>ModRM:r/m (w)</td>
<td>ModRM:reg (r)</td>
<td>CL</td>
<td>NA</td></tr></table>
<h2>Description</h2>
<p>The SHLD instruction is used for multi-precision shifts of 64 bits or more.</p>
<p>The instruction shifts the first operand (destination operand) to the left the number of bits specified by the third operand (count operand). The second operand (source operand) provides bits to shift in from the right (starting with bit 0 of the destination operand).</p>
<p>The destination operand can be a register or a memory location; the source operand is a register. The count operand is an unsigned integer that can be stored in an immediate byte or in the CL register. If the count operand is CL, the shift count is the logical AND of CL and a count mask. In non-64-bit modes and default 64-bit mode; only bits 0 through 4 of the count are used. This masks the count to a value between 0 and 31. If a count is greater than the operand size, the result is undefined.</p>
<p>If the count is 1 or greater, the CF flag is filled with the last bit shifted out of the destination operand. For a 1-bit shift, the OF flag is set if a sign change occurred; otherwise, it is cleared. If the count operand is 0, flags are not affected.</p>
<p>In 64-bit mode, the instruction’s default operation size is 32 bits. Using a REX prefix in the form of REX.R permits access to additional registers (R8-R15). Using a REX prefix in the form of REX.W promotes operation to 64 bits (upgrading the count mask to 6 bits). See the summary chart at the beginning of this section for encoding data and limits.</p>
<h2>Operation</h2>
<pre>IF (In 64-Bit Mode and REX.W = 1)
    THEN COUNT ← COUNT MOD 64;
    ELSE COUNT ← COUNT MOD 32;
FI
SIZE ← OperandSize;
IF COUNT = 0
    THEN
         No operation;
    ELSE
         IF COUNT &gt; SIZE
              THEN (* Bad parameters *)
                    DEST is undefined;
                    CF, OF, SF, ZF, AF, PF are undefined;
              ELSE (* Perform the shift *)
                    CF ← BIT[DEST, SIZE – COUNT];
                    (* Last bit shifted out on exit *)
                    FOR i ← SIZE – 1 DOWN TO COUNT
                         DO
                              Bit(DEST, i) ← Bit(DEST, i – COUNT);
                         OD;
                    FOR i ← COUNT – 1 DOWN TO 0
                         DO
                              BIT[DEST, i] ← BIT[SRC, i – COUNT + SIZE];
                         OD;
         FI;
FI;</pre>
<h2>Flags Affected</h2>
<p>If the count is 1 or greater, the CF flag is filled with the last bit shifted out of the destination operand and the SF, ZF, and PF flags are set according to the value of the result. For a 1-bit shift, the OF flag is set if a sign change occurred; otherwise, it is cleared. For shifts greater than 1 bit, the OF flag is undefined. If a shift occurs, the AF flag is unde-fined. If the count operand is 0, the flags are not affected. If the count is greater than the operand size, the flags are undefined.</p>
<h2>Protected Mode Exceptions</h2>
<table class="exception-table">
<tr>
<td>#GP(0)</td>
<td>
<p>If the destination is located in a non-writable segment.</p>
<p>If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.</p>
<p>If the DS, ES, FS, or GS register contains a NULL segment selector.</p></td></tr>
<tr>
<td>#SS(0)</td>
<td>If a memory operand effective address is outside the SS segment limit.</td></tr>
<tr>
<td>#PF(fault-code)</td>
<td>If a page fault occurs.</td></tr>
<tr>
<td>#AC(0)</td>
<td>If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.</td></tr>
<tr>
<td>#UD</td>
<td>If the LOCK prefix is used.</td></tr></table>
<h2>Real-Address Mode Exceptions</h2>
<table class="exception-table">
<tr>
<td>#GP</td>
<td>If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.</td></tr>
<tr>
<td>#SS</td>
<td>If a memory operand effective address is outside the SS segment limit.</td></tr>
<tr>
<td>#UD</td>
<td>If the LOCK prefix is used.</td></tr></table>
<h2>Virtual-8086 Mode Exceptions</h2>
<table class="exception-table">
<tr>
<td>#GP(0)</td>
<td>If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.</td></tr>
<tr>
<td>#SS(0)</td>
<td>If a memory operand effective address is outside the SS segment limit.</td></tr>
<tr>
<td>#PF(fault-code)</td>
<td>If a page fault occurs.</td></tr>
<tr>
<td>#AC(0)</td>
<td>If alignment checking is enabled and an unaligned memory reference is made.</td></tr>
<tr>
<td>#UD</td>
<td>If the LOCK prefix is used.</td></tr></table>
<h2>Compatibility Mode Exceptions</h2>
<p>Same exceptions as in protected mode.</p>
<h2>64-Bit Mode Exceptions</h2>
<table class="exception-table">
<tr>
<td>#SS(0)</td>
<td>If a memory address referencing the SS segment is in a non-canonical form.</td></tr>
<tr>
<td>#GP(0)</td>
<td>If the memory address is in a non-canonical form.</td></tr>
<tr>
<td>#PF(fault-code)</td>
<td>If a page fault occurs.</td></tr>
<tr>
<td>#AC(0)</td>
<td>If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.</td></tr>
<tr>
<td>#UD</td>
<td>If the LOCK prefix is used.</td></tr></table></body></html>